/*
 * PruebaEuropeana.java - hackaton2011
 * (C) 2011 Digibis S.L.
 */
package com.digibis.europeana4j.test;

import java.util.List;

import com.digibis.europeana4j.EuropeanaConnection;
import com.digibis.europeana4j.EuropeanaItem;
import com.digibis.europeana4j.EuropeanaQuery;
import com.digibis.europeana4j.EuropeanaResults;
import com.digibis.europeana4j.adv.EuropeanaComplexQuery;

/**
 * @author Administrador
 */
public class Europeana4jMain {

    public static void main(String[] args) {
        try {
            long ms0 = System.currentTimeMillis();

            String apiKey = "";

            EuropeanaQuery europeanaQuery = new EuropeanaQuery();
            // busq.setWholeSubQuery
            // ("Interior of the mausoleum of Itimad-al-Daula, Agra 1800");
            europeanaQuery.setCreator("picasso");
            europeanaQuery.setType(EuropeanaComplexQuery.TYPE.IMAGE);
            europeanaQuery.setNotProvider("Hispana");
            EuropeanaConnection europeanaConnection = new EuropeanaConnection(apiKey);
            EuropeanaResults res = europeanaConnection.search(europeanaQuery, 1);
            System.out.println("Query: " + europeanaQuery.getSearchTerms());
            System.out.println("Query url: " + europeanaQuery.getQueryUrl(europeanaConnection));
            System.out.println("Results: " + res.getItemCount() + " / " + res.getTotalResults());
            if (res.getItemCount() > 0) {
                List<EuropeanaItem> items = res.getAllItems();
                for (int i = 0; i < items.size(); i++) {
                    EuropeanaItem item = items.get(i);
                    System.out.println();
                    System.out.println("**** " + (i + 1));
                    System.out.println("Title: " + item.getTitle());
                    System.out.println("Europeana URL: " + item.getObjectURL());
                    System.out.println("Type: " + item.getType());
                    System.out.println("Creator: " + item.getCreator());
                    System.out.println("Thumbnail: " + item.getBestThumbnail());
                    System.out.println("Data provider: "
                            + item.getDataProvider());
                }
            }

            // String json = europeana.searchJsonPage (busq, 1);
            // System.out.println (json);

            // ThumbnailsAccessor thumber = new ThumbnailsAccessor (europeana);
            // File dir = new File
            // ("C:\\Proj\\Java\\hackaton2011\\test\\thumbs_women");
            // List itemsOk = thumber.copyThumbnails (busq, dir, 1000);
            // System.out.println ("*** Elementos generados: " +
            // itemsOk.size());

            System.out.println();

            long t = System.currentTimeMillis() - ms0;
            System.out.println("*** OK!: " + (t / 1000d) + " seg.");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
